<?php include_once './application/views/sys_admin/common/header.php';  ?>
<script>
function editpayment(id){
	if(id>0){
		$( "#dialog" ).dialog({
			height:350,
			width:500,
			modal:true, //蒙层（弹出会影响页面大小）
			title:'编辑接口参数'
		});
		
		$( "#id").val(id);
		
		$.ajax({
			type: "POST",
			url: "/sys_admin/payment/pay_synchronize",
			data: "id="+$("#id").val(),
			success: function(ret){
				$("#paymentnid").html('<td class="tableleft">接口名称</td><td>'+ret.msg.name+'</td><td class="tableleft">标识</td><td>'+ret.msg.nid+"</td>");
				$("#member_id").val(ret.msg.member_id);
				$("#privateKey").val(ret.msg.privateKey);
				$("#payment_order").val(ret.msg.payment_order);
				$("#description").val(ret.msg.description);
				$("input[name=fstatus]:eq("+ret.msg.fstatus+")").attr("checked",'checked'); 
			},
			dataType: "json"
		});
	}
}

function submitpayment(){
	var id = $("#id").val();
	if(id > 0){
		$.ajax({
			type: "POST",
			url: "/sys_admin/payment/addparameter",
			data: "act=edit&id="+id+"&member_id="+$("#member_id").val()+"&privateKey="+$("#privateKey").val()+"&payment_order="+$("#payment_order").val()+"&description="+$("#description").val()+"&fstatus="+$('input:radio[name="fstatus"]:checked').val(),
			success: function(ret){
				$("#dialog" ).dialog();
				$("#msg").html(ret.msg);
				setTimeout(function(){
					$("#dialog" ).dialog("close");
				},5000);
				window.location.reload();
			},
			dataType: "json"
		});	
	}
}

function remove(id){
	if(confirm('你确定要删除?'))
	{
		if(id > 0){
			$.ajax({
				type: "POST",
				url: "/sys_admin/payment/addparameter",
				data: "act=delete&id="+id,
				success: function(ret){
					window.location.reload();
				},
				dataType: "json"
			});	
		}	
	}
}
</script>
<div id="dialog" title="系统提示" style="display:none;">
	<div id="msg" style="text-align:center;color:red">&nbsp;</div>
	<input type="hidden" name="id" id="id" />
	<table class="table table-bordered table-hover m10">
		<tr id="paymentnid"></tr>
	   	<tr>
	        <td class="tableleft">商户号 </td>
	        <td><input type="text" name="member_id" id="member_id" style="width: 100px;" /> </td>
	        <td class="tableleft">支付密钥 </td>
	        <td><input type="text" name="privateKey" id="privateKey" style="width: 100px;" /> </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft">排序 </td>
	        <td><input type="text" name="payment_order" id="payment_order" style="width: 100px;" /> </td>
	        <td class="tableleft">是否启用 </td>
	        <td><input type="radio" name="fstatus" value="0" id="fstatus"/>是&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="fstatus" value="1" id="fstatus" />否 </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft">描述 </td>
	        <td colspan="3"><input type="text" name="description" id="description"  style="width: 300px;" /> </td>
	   	</tr>
	 </table>
	<div style="text-align:center;">
		<input type="button" style="width: 60px; height:24px" value="关闭" onclick="$('#dialog').dialog('close');"/>
		<input type="button" style="width: 60px; height:24px" value="修改" onclick="submitpayment();" />
	</div>
</div>
<div class=" definewidth m20">
		<table class="table table-bordered table-hover definewidth m10">
			 <thead>
			    <tr>
			      <th><strong>ID</strong></th>
					<th><strong>接口名称</strong></th>
					<th><strong>标识</strong></th>
					<th><strong>商户号</strong></th>
					<th><strong>支付密钥</strong></th>
					<th><strong>排序</strong></th>
					<th><strong>是否启用</strong></th>
					<th><strong>操作</strong></th>
			    </tr>
			   </thead>
			   <?php foreach($list as $key=>$info){
			  		$tmp = unserialize($info['config']);
			  	?>
			  <tr>
				<td><?php echo $info['id'];?></td>
				<td><?php echo $info['name'];?></td>
				<td><?php echo $info['nid'];?></td>
				<td><?php echo $tmp['member_id'];?></td>
				<td><?php echo $tmp['PrivateKey'];?></td>
				<td><?php echo $info['payment_order'];?></td>
				<td><?php echo $payment_fstatus[$info['fstatus']];?></td>
				<td><a  href="javascript:editpayment(<?php echo $info['id'];?>);" >修改 </a> </td>
			  </tr>
			  <?php }?>
			  	<tr>
			  	<td colspan="12"  class="invbd_page"><?php echo $this->pagination->create_links();?></td>
			  	</tr>
		</table>
</div>